package cn.francis.shen1;

import com.sun.deploy.net.HttpResponse;
import com.sun.javafx.binding.StringFormatter;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.text.DateFormatter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@Profile(value = {"prod"})
@RestController
@RequestMapping("rest")
public class Rest {

    @Autowired
    private RabbitTemplate rabbitTemplate1;

    @GetMapping("/{length}")
    public Object send(@PathVariable("length") int length) {
        for (int i = 0; i < length; i++) {
            //
            String sendMsg = StringFormatter.format("[hello1] > %s > %s", i, LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyMMddHHmmss.ms"))).getValue();
            System.out.println("RestApiSender : " + sendMsg);
            this.rabbitTemplate1.convertAndSend("helloQueue", sendMsg);
        }
        return "success:ok";
    }
}
